Skip to content

feat(k8s)#188

Merged
marcelklehr merged 4 commits intomainfrom
feat/k8s
Feb 25, 2026
Merged

feat(k8s)#188
marcelklehr merged 4 commits intomainfrom
feat/k8s

Conversation

@marcelklehr
Copy link
Member

SIGTERM is used by k8s to signal impending deletion of pods

@marcelklehr marcelklehr changed the title feat(sigterm): Listen for SIGTERM to stop listening for tasks feat(k8s) Feb 17, 2026
@oleksandr-nc
Copy link
Contributor

oleksandr-nc commented Feb 17, 2026

Maybe we can test this idea:

start_bg_task()
yield
SIGTERM_RECEIVED.set()  # Uvicorn will handle SIGTERM on it's own? https://github.com/fastapi/fastapi/issues/2928

Idea behind this:

  1. Uvicorn catches SIGTERM
  2. Uvicorn triggers lifespan shutdown
  3. Background thread finishes current task, sees the event, breaks out
  4. Process exits cleanly

This will also be a benefit for usual docker installations

Signed-off-by: Marcel Klehr <mklehr@gmx.net>
@marcelklehr
Copy link
Member Author

Yep, from my testing, I think we need to wait for the processing to be done in the lifetime handler to avoid it shutting down prematurely.

Signed-off-by: Marcel Klehr <mklehr@gmx.net>
@marcelklehr
Copy link
Member Author

Added a TASK_POLLOING_INTERVAL setting

@marcelklehr marcelklehr marked this pull request as ready for review February 24, 2026 08:56
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
Copy link
Contributor

@oleksandr-nc oleksandr-nc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good 💪🏻

@marcelklehr
Copy link
Member Author

let's also see what copilot says :D

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to support Kubernetes pod termination by reacting to shutdown (SIGTERM-driven) and letting the service finish the in-flight task before stopping task polling/processing. It also makes the task polling interval configurable via an environment variable.

Changes:

  • Make the task polling interval configurable via TASK_POLLING_INTERVAL.
  • Add shutdown coordination between FastAPI lifespan teardown and the background worker thread.
  • Document TASK_POLLING_INTERVAL in appinfo/info.xml.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
lib/main.py Adds env-configurable polling and attempts graceful shutdown coordination with the background thread.
appinfo/info.xml Documents the new TASK_POLLING_INTERVAL environment variable.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: Marcel Klehr <mklehr@gmx.net>
@marcelklehr marcelklehr merged commit 65674f4 into main Feb 25, 2026
6 checks passed
@marcelklehr marcelklehr deleted the feat/k8s branch February 25, 2026 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants